package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRetailTask;
import com.ruoyi.system.service.ISysRetailTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 散户生产任务Controller
 *
 * @author ruoyi
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/system/task")
public class SysRetailTaskController extends BaseController
{
    @Autowired
    private ISysRetailTaskService sysRetailTaskService;

    /**
     * 查询散户生产任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/list")
    public TableDataInfo list( SysRetailTask sysRetailTask)
    {
        startPage();
        List<SysRetailTask> list = sysRetailTaskService.selectSysRetailTaskList(sysRetailTask);
        return getDataTable(list);
    }

    /**
     * 导出散户生产任务列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:export')")
    @Log(title = "散户生产任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRetailTask sysRetailTask)
    {
        List<SysRetailTask> list = sysRetailTaskService.selectSysRetailTaskList(sysRetailTask);
        ExcelUtil<SysRetailTask> util = new ExcelUtil<SysRetailTask>(SysRetailTask.class);
        util.exportExcel(response, list, "散户生产任务数据");
    }

    /**
     * 获取散户生产任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:task:query')")
    @GetMapping("/getTask")
    public AjaxResult getInfo(@RequestParam("rId") Long rId,@RequestParam("orderId") Long orderId)
    {
        return success(sysRetailTaskService.selectSysRetailTaskByRId(rId,orderId));
    }

    /**
     * 新增散户生产任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "散户生产任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRetailTask sysRetailTask)
    {
        return toAjax(sysRetailTaskService.insertSysRetailTask(sysRetailTask));
    }

    /**
     * 修改散户生产任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:edit')")
    @Log(title = "散户生产任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRetailTask sysRetailTask)
    {
        return toAjax(sysRetailTaskService.updateSysRetailTask(sysRetailTask));
    }

    /**
     * 删除散户生产任务
     */
    @PreAuthorize("@ss.hasPermi('system:task:remove')")
    @Log(title = "散户生产任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(sysRetailTaskService.deleteSysRetailTaskByRIds(rIds));
    }
}
